package com.hong.utils;

import com.hong.dto.UserDTO;
import com.hong.entity.User;

public class UserHolder {
    // 定义一个ThreadLocal，用于存放用户信息
    private static final ThreadLocal<UserDTO> tl = new ThreadLocal<>();//类加载时完成初始化

    public static void saveUser(UserDTO user){
        tl.set(user);
    }

    public static UserDTO getUser(){
        return tl.get();
    }

    public static void removeUser(){
        tl.remove();// 从当前线程中移除对应的ThreadLocal变量，避免内存泄漏
    }
}
